//
//  main.m
//  结构体作为对象的属性
//
//  Created by 许文娟 on 2024/1/15.
//

#import <Foundation/Foundation.h>

typedef struct {
    int year;
    int month;
    int day;
} Date;

@interface Student : NSObject
{
    @public
    NSString *_name;
    Date _birthday;
}

-(void)say;
@end

@implementation Student

-(void)say
{
    NSLog(@"name=%@,year=%i,month=%i,day=%i",_name,_birthday.year,_birthday.month,_birthday.day);
}

@end

int main(int argc, const char * argv[]) {
//    创建学生对象
    Student *stu=[Student new];
    //设置对象的属性
    stu->_name=@"lnj";
    //结构体只能在定义的时候初始化
    //系统并不清处它是数组还是结构体
    stu->_birthday=(Date){ 1989,1,14};
    //让学生说出自己的姓名和生日
    [stu say];
    
    Date d1 ={1999,1,5};
    Date d2;
    d2=d1;//本质是将d1所有属性的值都拷贝了一份赋值给d2
    
    d2.year=2000;
    printf("d1=year=%i\n",d1.year);
    printf("d2=year=%i\n",d2.year);
    
    return 0;
}
